<template>
	<div class="home-icon">
		<swiper :options="swiperOption" v-if="swiperLen">
		    <swiper-slide v-for="(page, index) in pages" :key="index">
		    	<div class="icon-wrap" v-for="icon in page" :key="icon.id">
					<div class="icon-img-wrap">
						<img :src="icon.imgUrl" class="icon-img">
					</div>
					<p class="icon-name">{{icon.desc}}</p>
				</div>
		    </swiper-slide>
	  	</swiper>
	</div>
</template>

<script>
export default {
  name: 'HomeIcon',
  props: {
  	iconList: {
  		type: Array,
  		required: true
  	}
  },
  data() {
    return {
      swiperOption: {}
    };
  },
  computed: {
    pages() {
      const pages = [];
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    },
    swiperLen() {
    	return this.iconList.length
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~styles/mixin.styl'
	.home-icon
		width: 100%
		height: 0
		padding-bottom: 50%
		overflow: hidden
		.icon-wrap
			width: 25%
			height: 0
			padding-bottom: 25%
			posr()
			fl()
			.icon-img-wrap
				posa()
				top: 0
				left: 0
				right: 0
				bottom: .24rem
				padding: .1rem
			.icon-img
				display: block
				height: 100%
				margin: .1rem auto
			.icon-name
				width: 100%
				posa()
				bottom: 0
				text-align: center
</style>
